package com.youli.gb.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

import com.youli.gb.model.SysUser;
import com.youli.gb.service.ISysUserService;
import com.youli.gb.service.impl.SysUserServiceImpl;
import com.youli.gb.utils.TransactionHandler;

@WebServlet("/user.do")
public class SysUserServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;	
	
	//注入service对象
	private ISysUserService userService = new SysUserServiceImpl();
       
    public SysUserServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");	
		
		String type = request.getParameter("type");
		//type="getAll";
		
		
		if(type.equals("getAll")) {
			List<SysUser> users  = userService.getAll();			
			request.setAttribute("users", users);			
			request.getRequestDispatcher("user/users.jsp").forward(request, response);
			}
		
		
	}
		
		
		

	
	
		
		

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
